﻿@{
    ViewBag.Title = "菜单管理";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<link href="~/plugins/jquery-treegrid/css/jquery.treegrid.min.css" rel="stylesheet" />
<div class="wrapper wrapper-content  animated fadeInRight">
    <div class="ibox">
        <div class="ibox-content">
            <div id="toolbar" class="btn-group">
            </div>
            <table id="table"></table>
        </div>
    </div>
</div>
@section scripts
{
    <script src="~/plugins/bootstrapTableTree/bootstrap-table-treegrid.js"></script>
    <script src="~/plugins/jquery-treegrid/jquery.treegrid.min.js"></script>
    <script>
        var $table;

        $(function() {
            loadGrid();
        });

        function loadGrid() {
            $table = $("#table").bootstrapTable({
                url: '/admin/SysMenu/GetData',
                height: $(window).height(),
                striped: true,
                sidePagination: 'server',
                idField: 'id',
                columns: [
                    {field: 'ck',checkbox: true},
                    { field: 'menu_name', title: '名称', align: 'left' },
                    { field: 'menu_url', title: '菜单路径', align: 'center' },
                    { field: 'menu_icon', title: '菜单图片', align: 'center' },
                    { field: 'menu_sort', title: '排序', align: 'center' },
                    { field: 'remark', title: '排序', align: 'center' },
                    { field: 'id', title: '操作', align: 'center',formatter:renderOpts }
                ],
                treeShowField: 'menu_name',
                parentIdField: 'parent_id',
                onLoadSuccess: function (data) {
                    $table.treegrid({
                        // initialState: 'collapsed',
                        treeColumn: 1,
                        // expanderExpandedClass: 'glyphicon glyphicon-minus',
                        // expanderCollapsedClass: 'glyphicon glyphicon-plus',
                        onChange: function() {
                            $table.bootstrapTable('resetWidth');
                        }
                    });
                }
                // bootstrap-table-treetreegrid.js 插件配置
            });
            jutils.initToolBarRole('#toolbar');

        }
        function renderOpts(v, d, i) {
            return jutils.initToolBarRow(v);
        }
        function renderIcon(rowdata, index, value) {
            return '<i class="' + value+'"></i>';
        }

        function add() {
            var url = '/admin/sysmenu/form';
            parent.$.altasTab.open({
                id: 'menuformTab',
                title: '菜单信息',
                url: url,
                close: function () {
                    $table.bootstrapTable('refresh');
                }
            });
        }
        function edit(obj) {
            var id = $(obj).data('id');
            var url = '/admin/sysmenu/form/' + id;
            parent.$.altasTab.open({
                id: 'menuformTab',
                title: '菜单信息',
                url: url,
                close: function () {
                    $table.bootstrapTable('refresh');
                }
            });
        }
        function del(obj) {

            var id = $(obj).data('id');

            jutils.confirm('确认删除选中的数据吗', function () {

                jutils.ajaxGet('/admin/sysmenu/del', { ids: id }, function () {
                    jutils.success('删除成功');
                    $table.bootstrapTable('refresh');
                });
            });
        }
        function batchDel() {
            var rows = $table.bootstrapTable('getSelections');
            if (rows.length === 0) {
                jutils.warn('请选中需要删除的数据行');
                return;
            }
            var ids = [];
            for (var i = 0; i < rows.length; i++) {

                ids.push(rows[i].id);

            }
          
            jutils.confirm('确认删除选中的数据吗', function () {
               
                jutils.ajaxGet('/admin/sysmenu/del', { ids: ids.join() }, function () {
                    jutils.success('删除成功');
                    $table.bootstrapTable('refresh');
                });
            });
        }

        function refresh() {
            $table.bootstrapTable('refresh');
        }
    </script>

}